package com.zhentao.controller;

import com.zhentao.common.Result;
import com.zhentao.service.SuccessCaseService;
import com.zhentao.vo.SuccessCaseVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 成功案例控制器
 */
@RestController
@RequestMapping("/api/success-case")
public class SuccessCaseController {
    
    @Autowired
    private SuccessCaseService successCaseService;
    
    /**
     * 获取成功案例详情
     * 
     * @param caseNo 案例编号
     * @return 案例详情
     */
    @GetMapping("/detail/{caseNo}")
    public Result<SuccessCaseVO> getCaseDetail(@PathVariable String caseNo) {
        try {
            SuccessCaseVO caseDetail = successCaseService.getCaseDetail(caseNo);
            if (caseDetail == null) {
                return Result.error("案例不存在或已下架");
            }
            return Result.success(caseDetail);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("获取案例详情失败：" + e.getMessage());
        }
    }
    
    /**
     * 获取成功案例列表
     * 
     * @return 案例列表
     */
    @GetMapping("/list")
    public Result<List<SuccessCaseVO>> getCaseList() {
        try {
            List<SuccessCaseVO> caseList = successCaseService.getCaseList();
            return Result.success(caseList);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("获取案例列表失败：" + e.getMessage());
        }
    }
    
    /**
     * 获取案例时间线
     * 
     * @param caseNo 案例编号
     * @return 时间线列表
     */
    @GetMapping("/timeline/{caseNo}")
    public Result<?> getTimeline(@PathVariable String caseNo) {
        try {
            return Result.success(successCaseService.getTimeline(caseNo));
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("获取时间线失败：" + e.getMessage());
        }
    }
}

